package cz.anime.ppro.beans;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.web.context.WebApplicationContext;

import cz.anime.ppro.logic.EventComponent;
import cz.anime.ppro.model.Event;
import cz.anime.ppro.model.Webuser;

@Component
@ManagedBean
@Scope(WebApplicationContext.SCOPE_REQUEST)
public class UserEventsAdministrationBean {

	private List<Event> userEvents;
	
	@Autowired
	private EventComponent eventComponent;
	
	@PostConstruct
	public void init(){
		List<Event> events = eventComponent.getEvents();
		userEvents = new ArrayList<Event>();
		for (Event event : events) {
				for (Webuser user : event.getWebusers()) {
					if (user.getId() != 0 && user.getId() == getUser()) userEvents.add(event); 
				}	
		}
	}
	
	private int getUser(){
		return 2;
	}

	public List<Event> getUserEvents() {
		return userEvents;
	}

	public void setUserEvents(List<Event> userEvents) {
		this.userEvents = userEvents;
	}
}
